﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QLNS.aspFrm
{
    public partial class frmTrinhDoNgoaiNgu : System.Web.UI.Page
    {
        public string IDCB { get { return Request.QueryString["id"].ToString(); } }
        protected void Page_Load(object sender, EventArgs e)
        {
            System.Data.DataTable dtTK = MakeTable();
            //doan nay co the bo 
            List<QLNS.TrinhDoNgoaiNgu> lstTK = QLNS.Models.TrinhDoNgoaiNguModels.GetTrinhDoNNTheoCanBo(Convert.ToInt32(Request["id"].ToString()));
            foreach (var r in lstTK)
            {
                System.Data.DataRow row;
                row = dtTK.NewRow();
                this.FillDataRow(row, r);
                dtTK.Rows.Add(row);
            }

            //Tao 5 level cho phong ban


            CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            string strRptPath = Server.MapPath("~/") + "Reports//Report_TrinhDoNgoaiNgu.rpt";
            //Loading Report
            rd.Load(strRptPath);

            // Setting report data source
            if (dtTK != null && dtTK.GetType().ToString() != "System.String")
                rd.SetDataSource(dtTK);


            CrystalReportViewer1.ReportSource = rd;

        }
        private void FillDataRow(System.Data.DataRow row, QLNS.TrinhDoNgoaiNgu r)
        {
            //System.Data.DataRow row = new System.Data.DataRow();
            System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CreateSpecificCulture("en-GB");

            row["STT"] = Convert.ToInt32(r.STT);
            CapNgoaiNgu cnn = QLNS.Models.CapNgoaiNguModels.GetChiTietDSCapNgoaiNgu((int)r.IDTrinhDo);
            row["CapTrinhDo"] = cnn.Ten;
            row["Ten"] = r.Ten;
            //row["NgayCap"] = r.NgayCap.ToString() == "" ? DateTime.Parse("01/1/1900", ci.DateTimeFormat) : r.NgayCap;
            if (r.NgayCap == DateTime.Parse("01/1/1900"))
            {
                row["NgayCap"] = "";
            }
            else
            {
                string[] words = r.NgayCap.ToString().Split(' ');
                //s = s.Substring(0, 10);
                row["NgayCap"] = words[0];
            }

            //return row;
        }
        private System.Data.DataTable MakeTable()
        {
            // Create a new DataTable.
            System.Data.DataTable table = new System.Data.DataTable("Table");

            // Declare variables for DataColumn and DataRow objects.
            System.Data.DataColumn column;

            // Create new DataColumn, set DataType, 


            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.Int32");
            column.ColumnName = "STT";
            column.Caption = "STT";
            // Add the column to the table.
            table.Columns.Add(column);
            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "Ten";
            column.Caption = "Tên";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "CapTrinhDo";
            column.Caption = "Trình độ";
            // Add the column to the table.
            table.Columns.Add(column);

            // Create second column.
            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "NgayCap";
            column.Caption = "Ngày cấp";
            // Add the column to the table.
            table.Columns.Add(column);


            return table;
        }
    }
}